package com.kycxika.app.activity.base;

import android.app.Activity;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;
import com.kycxika.app.R;

/**
 * Created by kyc on 2017/5/2.
 */
public abstract class BaseActivity extends BasePhotoActivity{

    private View mBack;
    private TextView mTitle;
    private View mTitle_image;
    private TextView title_right_txt;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayout());

        initView();
        initData();
        initListener();
    }

    public void getVisibility(boolean visi, final Activity activity){
        if(visi) {
            mBack.setVisibility(View.VISIBLE);
            mBack.setEnabled(true);
            mBack.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    leftBlack();
                    activity.finish();
                }
            });
        }else {
            mBack.setVisibility(View.INVISIBLE);
            mBack.setEnabled(false);
        }
    }

    public void setTop(View view){
        mBack = view.findViewById(R.id.back);
        mTitle = (TextView) view.findViewById(R.id.title);
        mTitle_image = view.findViewById(R.id.title_image);
        title_right_txt = (TextView) view.findViewById(R.id.title_right_txt);
    }

    public void rightVisibility(String str,int img){
        if(!TextUtils.isEmpty(str)){
            title_right_txt.setText(str);
            title_right_txt.setVisibility(View.VISIBLE);
            title_right_txt.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    rightonClick();
                }
            });
        }else if(img != -1){
            mTitle_image.setBackgroundResource(img);
            mTitle_image.setVisibility(View.VISIBLE);
        }else {
            title_right_txt.setVisibility(View.INVISIBLE);
            mTitle_image.setVisibility(View.GONE);
        }
    }

    public void getTitle(String title){
        mTitle.setText(title);
    }

    @Override
    public Resources getResources() {
        Resources res = super.getResources();
        Configuration config=new Configuration();
        config.setToDefaults();
        res.updateConfiguration(config,res.getDisplayMetrics() );
        return res;
    }

    /*
    初始化控件
     */
    protected abstract void initView();

    /*
    初始化数据
     */
    protected abstract void initData();

    /*
    设置监听事件
     */
    protected abstract void initListener();

    /*
    加载布局
     */
    public abstract int getLayout();

    public void ToastWarning(String str) {
        //Toasty.warning(this, str, Toast.LENGTH_SHORT).show();
    }

    public void ToastSuccess(String str){
       // Toasty.success(this, str, Toast.LENGTH_SHORT).show();
    }

    public void rightonClick(){

    }

    public void leftBlack(){}
}
